//
//  XYOriginateImageView.swift
//  SinaWB_XY
//
//  Created by 小熊猫 on 15/10/20.
//  Copyright © 2015年 小熊猫. All rights reserved.
//

import UIKit
import SDWebImage

class XYOriginateImageView: UIImageView {
    
    //图片的gif图标
    private var gifImage:UIImageView?
    

    //缩略图
    var thumbnail_pic:String?{
        didSet{
            //如果有图片信息,就加载
            if let pic = thumbnail_pic{
                sd_setImageWithURL(NSURL(string: pic), placeholderImage: UIImage(named: "timeline_image_placeholder"))
                if pic.hasSuffix("gif"){
                    self.gifImage!.hidden = false
                }else{
                    self.gifImage!.hidden = true
                }
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        contentMode = UIViewContentMode.ScaleAspectFill
        clipsToBounds = true
        
        //添加gif图标
        let gifImage = UIImageView(image: UIImage(named: "timeline_image_gif"))
        self.gifImage = gifImage
        addSubview(gifImage)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        self.gifImage!.x = self.width - self.gifImage!.width
        self.gifImage!.y = self.height - self.gifImage!.height
    }
}
